package wb.is.besti.edu.cd.javalibgame;

import android.content.Context;
import android.graphics.Typeface;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.Switch;
import android.widget.TextView;

/**
 * Created by asus on 2017/12/17.
 */

public class AddCard extends FrameLayout  {
    private View background;
    private TextView textView;
    private int num = 1;
    public AddCard(@NonNull Context context) {
        super(context);
        setBackgroundResource(R.drawable.shape_green);
        LayoutParams layoutParams = null;
        background = new View(getContext());
        layoutParams = new LayoutParams(-1,-1);
        layoutParams.setMargins(10,10,0,0);
        background.setBackgroundColor(0x33ffffff);
        addView(background,layoutParams);
        textView = new TextView(getContext());
        layoutParams =new LayoutParams(-1,-1);
        layoutParams.setMargins(10,10,0,0);
        textView.setTypeface(Typeface.createFromAsset(getContext().getAssets(),"fonts/typesc.ttf"));
        textView.setTextSize(20);

        textView.setGravity(Gravity.CENTER);
        addView(textView,layoutParams);
        setNum(1);
    }

    public AddCard(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
        if (num<=0){
            textView.setText("");
        }
        else {
            textView.setText(num+"");
        }
        switch (num){
            case 1:
                textView.setBackgroundColor(0xffeee4da);
                break;
            case 2:
                textView.setBackgroundColor(0xffede0c8);
                break;
            case 3:
                textView.setBackgroundColor(0xfff2b179);
                break;
            case 4:
                textView.setBackgroundColor(0xfff59563);
                break;
            case 5:
                textView.setBackgroundColor(0xfff67c5f);
                break;
            case 6:
                textView.setBackgroundColor(0xfff65e3b);
                break;
            case 7:
                textView.setBackgroundColor(0xffedcf72);
                break;
            case 8:
                textView.setBackgroundColor(0xffedcc61);
                break;
            case 9:
                textView.setBackgroundColor(0xffedc850);
                break;
            case 10:
                textView.setBackgroundColor(0xffedc53f);
                break;
            default:
                textView.setBackgroundColor(0xffedc22e);
                break;
        }
    }


    public boolean equals(AddCard a) {
        return getNum()==a.getNum();
    }
    protected AddCard clone(){
        AddCard  c = new AddCard(getContext());
        c.setNum(getNum());
        return c;
    }
    public TextView getTextView(){
        return textView;
    }
}
